package com.lcc.mapper;

import com.lcc.pojo.Emp;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {

    /**
     * 返回总记录数
     * @return
     */
    @Select("select count(*) from tlias.emp")
    public Long count();


    /*
     * 分页查询-使用PageHelper插件
     * */
    public List<Emp> list(String name, Short gender,LocalDate begin, LocalDate end);

    //批量删除
    void delete(List<Integer> ids);

    //新增员工 password是默认设置密码
    @Insert("INSERT into tlias.emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "value (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @Select("SELECT * from tlias.emp where id= #{id}")
    Emp getById(Integer id);

    /**
     * 更新员工信息
     * @param emp
     */
    void update(Emp emp);

    /**
     * 用户和密码查询员工
     * @return
     */
    @Select("select * from tlias.emp where username = #{username} and password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);

    /*
     * 根据部门ID删除该部门下的员工
     * */
    @Delete("delete from tlias.emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);

}
